unit UConciliacaoBancario;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UFomCadastro, DBCtrls, StdCtrls, Buttons, ExtCtrls, DB,
  DBTables, Grids, DBGrids, Mask, ToolEdit;

type
  TFConciliacaoBancario = class(TFormCadastro)
    DBGrid1: TDBGrid;
    DBGrid2: TDBGrid;
    BitBtn1: TBitBtn;
    dsConciliacao: TDataSource;
    dsLancamento: TDataSource;
    Data1: TDateEdit;
    dblkcoNTA: TDBLookupComboBox;
    Label1: TLabel;
    Label2: TLabel;
    DSConta: TDataSource;
    Query1: TQuery;
    DSClassFin: TDataSource;
    DSCenCust: TDataSource;
    Query2: TQuery;
    Query3: TQuery;
    DSContConta: TDataSource;
    DSESpe: TDataSource;
    Query4: TQuery;
    Tconciliacao: TQuery;
    TLancamento: TQuery;
    BitBtn2: TBitBtn;
    Label3: TLabel;
    Label4: TLabel;
    pnInfo: TPanel;
    Label5: TLabel;
    Label6: TLabel;
    dblPlanoConta: TDBLookupComboBox;
    dblCentroCusto: TDBLookupComboBox;
    Label7: TLabel;
    Label8: TLabel;
    dblContaContabil: TDBLookupComboBox;
    dblEspecie: TDBLookupComboBox;
    btnOk: TBitBtn;
    btnCancel: TBitBtn;
    procedure TconciliacaoBeforeOpen(DataSet: TDataSet);
    procedure TLancamentoBeforeOpen(DataSet: TDataSet);
    procedure BitBtn2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BtnIncluirClick(Sender: TObject);
    procedure BtnEditarClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure BtnSalvarClick(Sender: TObject);
    procedure BtnCancelarClick(Sender: TObject);
    procedure BtnFecharClick(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FConciliacaoBancario: TFConciliacaoBancario;

implementation

uses ugeral, UConciliacaoBancaria;

{$R *.dfm}

procedure TFConciliacaoBancario.TconciliacaoBeforeOpen(DataSet: TDataSet);
const
  SQL= 'select * from MOVIMENTO_BANCARIO  where (dat_lancamento2 = %s)  and (cod_conta = %s)';
begin
  inherited;
  Tconciliacao.SQL.Clear;
  Tconciliacao.SQL.Add(Format(SQL,[QUOTEDSTR(FormataDataBanco(Data1.Date)),
                                   QUOTEDSTR(dsconta.dataset.fieldbyname('IDENTIFICADOR_CONTA_BANCO').asstring)]));
end;

procedure TFConciliacaoBancario.TLancamentoBeforeOpen(DataSet: TDataSet);
const
  SQL= 'SELECT * FROM LANCAMENTO WHERE (LANC_DATA BETWEEN %s AND = %s)';
begin
  inherited;
  TLancamento.SQL.Clear;
  TLancamento.SQL.Add(Format(SQL,[QUOTEDSTR(DATETOSTR(Data1.Date)),
                                  QUOTEDSTR(dblkcoNTA.KeyValue)]));
end;

procedure TFConciliacaoBancario.BitBtn2Click(Sender: TObject);
begin
  inherited;
  Tconciliacao.Open;
  TLancamento.open;
  BitBtn1.Enabled;
end;

procedure TFConciliacaoBancario.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
 ACTION := CAFREE;
 FConciliacaoBancaria := NIL;

end;

procedure TFConciliacaoBancario.BtnIncluirClick(Sender: TObject);
begin
  inherited;
  BitBtn2.Enabled := true;
  BitBtn1.Enabled := true;
end;

procedure TFConciliacaoBancario.BtnEditarClick(Sender: TObject);
begin
  inherited;
  BitBtn2.Enabled := true;
  BitBtn1.Enabled := true;
end;

procedure TFConciliacaoBancario.FormActivate(Sender: TObject);
begin
  inherited;
  BitBtn1.Enabled := false;
  BitBtn2.Enabled := false;
end;

procedure TFConciliacaoBancario.BtnSalvarClick(Sender: TObject);
begin
  inherited;
  BitBtn1.Enabled := false;
  BitBtn2.Enabled := false;
end;

procedure TFConciliacaoBancario.BtnCancelarClick(Sender: TObject);
begin
  inherited;
  BitBtn1.Enabled := false;
  BitBtn2.Enabled := false;
end;

procedure TFConciliacaoBancario.BtnFecharClick(Sender: TObject);
begin
  inherited;
  close;
end;

procedure TFConciliacaoBancario.BitBtn1Click(Sender: TObject);
begin
  inherited;
  pnInfo.Visible := true;
  dblPlanoConta.SetFocus;
end;

end.
